/*
package com.yx.system.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.yx.common.annotation.LoginUser2;
import com.yx.common.utils.PageUtils;
import com.yx.common.utils.Query;
import com.yx.common.utils.R;
import com.yx.modules.api.entity.TbChannel;
import com.yx.modules.api.service.TbChannelService;
import com.yx.modules.api.service.TbClickService;
import com.yx.system.dto.TbChannelDto;
import com.yx.system.entity.SysUser;
import com.yx.system.entity.TdOrder;
import com.yx.system.service.SysRoleService;
import com.yx.system.service.SysUserRoleService;
import com.yx.system.service.SysUserService;
import com.yx.system.service.TdOrderService;
import com.yx.utils.OrderUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



*/
/**
 * 渠道信息表
 * 
 * @author luo
 * @email www.baidu.com
 * @date 2018-08-29 14:01:37
 *//*

@RestController
@RequestMapping("sys/channel")
public class TbChannelController {
	@Autowired
	private TbChannelService channelService;

	@Autowired
	private SysUserService sysUserService;

	@Autowired
	private SysUserRoleService sysUserRoleService;

	@Autowired
	private TdOrderService tdOrderService;

	@Autowired
	private TbClickService tbClickService;
	
	*/
/**
	 * 列表
	 *//*

	@RequestMapping("/list")
	@RequiresPermissions("sys:channel:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TbChannel> channelList = channelService.queryList(query);
		int total = channelService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(channelList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	*/
/**
	 * 信息
	 *//*

	@RequestMapping("/info/{id}")
	@RequiresPermissions("channel:info")
	public R info(@PathVariable("id") Integer id){
		TbChannel channel = channelService.queryObject(id);
		
		return R.ok().put("channel", channel);
	}
	
	*/
/**
	 * 保存
	 *//*

	@RequestMapping("/save")
	@RequiresPermissions("channel:save")
	public R save(@RequestBody TbChannel channel){
		channelService.save(channel);
		//拼接创建url
		String c_url = "www.youwenyuedu.com?number="+channel.getId();
		channel.setCUrl(c_url);
		//创建后台用户
		SysUser sysUser = new SysUser();
		//生成随机的账号和密码
		String userName = OrderUtil.getAcount();
		String password = OrderUtil.getPassword();
		//在渠道信息中先保存
		channel.setCUser(userName);
		channel.setCPassword(password);
		//在后台用户中保存
		sysUser.setUsername(userName);
		sysUser.setPassword(DigestUtils.sha256Hex(password));
		sysUser.setCreateTime(new Date());
		sysUser.setEmail("");
		sysUser.setMobile(userName);
		sysUser.setIdentity(3);
		sysUser.setStatus(1);
		sysUser.setcId(channel.getId());
		//保存用户
		sysUserService.save(sysUser);
		//赋予固定角色权限
		sysUserRoleService.authorRole(sysUser.getUserId(),5L);
		//保存渠道
		channelService.update(channel);
		return R.ok();
	}
	
	*/
/**
	 * 修改
	 *//*

	@RequestMapping("/update")
	@RequiresPermissions("channel:update")
	public R update(@RequestBody TbChannel channel){
		channelService.update(channel);
		return R.ok();
	}
	
	*/
/**
	 * 删除
	 *//*

	@RequestMapping("/delete")
	@RequiresPermissions("channel:delete")
	public R delete(@RequestBody Integer[] ids){
		channelService.deleteChannel(ids);
		return R.ok();
	}


	*/
/*
	* 获取渠道点击数，订阅数，充值数统计列表
	*//*

	@RequestMapping("/listDto")
	public R listDto(@RequestParam Map<String, Object> params, @LoginUser2 SysUser sysUser){
		//查询列表数据
		Query query = new Query(params);
		if (sysUser.getIdentity()==3){
			query.put("id",sysUser.getcId());
		}
		List<TbChannel> channelList = channelService.queryList(query);
		int total = channelService.queryTotal(query);
		//初始化数据传输对象集合
		List<TbChannelDto> tbChannelDtos = new ArrayList<>();
		//循环查出的渠道信息
		for (TbChannel tbChannel:channelList){
			//新建数据传输对象
			TbChannelDto tbChannelDto = new TbChannelDto();
			//根据渠道id查询订阅总和
			Integer subscibeSum = tdOrderService.findSubscibeSumByCid(tbChannel.getId());
			//根据渠道id查询充值总和
			Integer rechargeSum = tdOrderService.findRechargeSumByCid(tbChannel.getId());
			//根据渠道id查询点击总和
			Integer clickSum = tbClickService.findClickSumByCid(tbChannel.getId());
			//赋值
			tbChannelDto.setId(tbChannel.getId());
			tbChannelDto.setcUrl(tbChannel.getCUrl());
			tbChannelDto.setcName(tbChannel.getCName());
			tbChannelDto.setcClick(clickSum);
			tbChannelDto.setcSubscibe(subscibeSum);
			tbChannelDto.setcRecharge(rechargeSum);
			//添加进集合
			tbChannelDtos.add(tbChannelDto);
		}
		PageUtils pageUtil = new PageUtils(tbChannelDtos, total, query.getLimit(), query.getPage());
		return R.ok().put("page",pageUtil);
	}

	*/
/*
	* 获取一条渠道记录的订阅记录
	*//*

	@RequestMapping("/subscibe")
	public R subscibe(Integer id){
		//首先根据渠道id查询到具体的渠道
		TbChannel tbChannel = channelService.queryObject(id);
		//再根据渠道id去查询所有对应的订阅记录
		List<TdOrder> tdOrders = tdOrderService.findSubscibeByCid(tbChannel.getId());
		return R.ok().put("subscibes",tdOrders);
	}

	*/
/*
	* 获取一条渠道记录的充值记录
	*//*

	@RequestMapping("/recharge")
	public R recharge(Integer id){
		//首先根据渠道id查询到具体的渠道
		TbChannel tbChannel = channelService.queryObject(id);
		//再根据渠道id去查询所有对应的充值记录
		List<TdOrder> tdOrders = tdOrderService.findRechargeByCid(tbChannel.getId());
		return R.ok().put("recharges",tdOrders);
	}

}
*/
